﻿using LD.Controls.ControlHelper;
using LD.Model;
using PubSub;
using System;
using System.Windows.Forms;

namespace LD
{
    public partial class FrmMachineInfo : FrmBase
    {
        public FrmMachineInfo()
        {
            InitializeComponent();
            this.FormClosing += FrmMachineInfo_FormClosing;
            FormScaler.ScaleForm(this, true);//自动缩放
            Init();
        }
        string id = Guid.NewGuid().ToString();
        private void FrmMachineInfo_FormClosing(object sender, FormClosingEventArgs e)
        {
            Hub.Default.Unsubscribe<TB_WIP>(id);
        }

        private void Init()
        {
           
            清除批头.Hide();
            清除吸嘴.Hide();
            Hub.Default.Subscribe<TB_WIP>(id, wip => UiUpdate(wip));
            //txt_total.DataBindings.Add("Text", WipHelper.Instance.WipData, "Input");

        }
        private void UiUpdate(TB_WIP wip)
        {
            this.Invoke(new Action(() =>
            {
                txt_throwNumber.Text = wip.NG.ToString();//抛料数量
                txt_SuckQuantity.Text = wip.Bitbits.ToString();//批头使用次数
                txt_NGrate.Text = wip.PaoLiaoYield.ToString();//抛料率
                txt_vacAlNum.Text = wip.vacAlNum.ToString();//真空报警数
                txt_vacNum.Text = wip.vacNum.ToString();//真空次数
                txt_vacAlRate.Text = wip.vacAlRate;//真空报警率
                txt_ProductNum.Text = wip.All.ToString();//所有产品
                txt_passNum.Text = wip.Pass.ToString();//所有pass的产品
                txt_FailNum.Text = wip.NG.ToString();//NG数量
                //  txt_avertime.Text = wip.           //平均锁附时间
                //txt_currentTime.Text= wip.         //当前锁附时间
                txt_Recent100OK.Text = wip.Pass100Yield.ToString();//100片良率
                txt_Nozzle.Text = wip.Nozzle.ToString();//吸嘴使用次数
                txt_Bitbits.Text = wip.Bitbits.ToString();//批头使用次数
                txt_barcode.Text=wip.Barcode.ToString();//条码
                txt_CT.Text = wip.CT.ToString();//CT时间
            }));
        }




        #region
        private void 清除吸嘴_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("\t确认要执行操作吗？\n\t即将清除吸嘴使用次数\n\t请确认压爪已更换", "确认", MessageBoxButtons.OKCancel);
            if (result == DialogResult.OK)
            {


            }
        }

        private void 清除批头_Click_1(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("\t确认要执行操作吗？\n\t即将清除批头使用次数\n\t请确认批头已更换", "确认", MessageBoxButtons.OKCancel);
            if (result == DialogResult.OK)
            {


            }
        }
        #endregion
    }

}
